package server.business.login.handler;

import com.core.initialize.Message;
import com.google.protobuf.GeneratedMessage;

import server.ServerEngin;
import server.ServerHandler;
import server.ServerTransportProxy;
import server.commonData.Player;
import server.commonData.User;
import server.messageId.S2CMessageId;
import server.msgBean.LoginMessage.ViewOtherInfoReq;
import server.msgBean.LoginMessage.ViewOtherInfoRes;

/**
 * 查看其他玩家信息
 * @author King
 *
 */
public class ViewOtherInfoHandler extends ServerHandler
{

	@Override
	public Class<? extends GeneratedMessage> initBodyClass()
	{
		return ViewOtherInfoReq.class;
	}

	@Override
	protected void handler(Message msg, User user) throws Throwable
	{
		ViewOtherInfoReq req = msg.getBody();
		Player player =  ServerEngin.getInstance().getCache().getUser(req.getUserId());
		msg.clearDate();
		msg.setModuleAction(S2CMessageId.Login.MODULE_ID, S2CMessageId.Login.VIEW_OTHER_INFO);
		ViewOtherInfoRes.Builder builder = ViewOtherInfoRes.newBuilder();
		builder.setUserId(req.getUserId());
		builder.setVipLevel(player.getVipLevel());
		builder.setWinNum(player.getWinNum());
		builder.setFailNum(player.getFailNum());
		builder.setName(player.getName());
		builder.setFaceIndex(player.getFace());
		builder.setMoney(player.getMoney());
		msg.setBody(builder);
		ServerTransportProxy.sendMsg(msg, user);
	}
}
